package com.example.test.domain;

import com.example.test.domain.group.validation.Create;
import com.example.test.domain.group.validation.Update;
import com.example.test.domain.group.json.BaseView;
import com.fasterxml.jackson.annotation.JsonView;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.util.Date;

/**
 * 基础实体类
 */
@Data
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
class Base {
    @Id
    @GeneratedValue
    @Null(groups = {Create.class})
    @NotNull(groups = {Update.class})
    @JsonView({BaseView.class})
    private Long id;

    @CreatedDate
    @Null(groups = {Create.class, Update.class})
    private Date createdDate;

    @LastModifiedDate
    @Null(groups = {Create.class, Update.class})
    private Date lastModifiedDate;
}
